﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.Xml.Linq;
using System.Threading;

namespace myChannel9
{
    public class VideoObject
    {
        public string Url { get; set; }
        public string Heading { get; set; }
        public string Type { get; set; }
        public string Posted { get; set; }
        public string PostedDetails { get; set; }
        public string PostedDate { get; set; }
        public string Image { get; set; }
        public string Image_large { get; set; }
        public string Lenght { get; set; }
        public string LenghtDetails { get; set; }
        public string Video { get; set; }
        public string Description { get; set; }
        public string Tags { get; set; }
        public bool Favorite { get; set; }

        public List<string> imageList { get; set; }
        public List<string> videoList { get; set; }
        public List<string> lenghtList { get; set; }

        public string getImage
        {
            get
            {
                string imageUrl = "";

                if (Image != null)
                {
                    imageUrl = Image;
                }
                else
                {
                    if (imageList != null)
                    {
                        if (imageList.Count >= 0)
                        {
                            imageUrl = imageList[imageList.Count-1];
                        }
                    }
                }
                
                return imageUrl;
            }
        }

        public string getVideo
        {
            get
            {
                string videoUrl = "";

                if (Video != null)
                {
                    videoUrl = Video;
                }
                else
                {
                    if (videoList != null)
                    {
                        var vi = (from v in videoList
                                  where v.Contains(".wmv")
                                  select v);

                        videoUrl = vi.Last().ToString();
                    }
                }

                return videoUrl;
            }
        }

        public string getPostedDetails
        {
            get
            {
                return "Date: " + PostedDetails;
            }
        }

        public string getLenght
        {
            get
            {
                string tempLenght = "";

                if (lenghtList != null)
                {
                    if (lenghtList.Count > 0)
                    {
                        tempLenght = lenghtList[0];

                        TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(tempLenght));
                        tempLenght = "";

                        if (t.Hours > 0)
                        {
                            tempLenght = t.Hours + ".";
                        }

                        if (t.Minutes > 9)
                        {
                            tempLenght += t.Minutes + ".";
                        }
                        else
                        {
                            tempLenght += "0" + t.Minutes + ".";
                        }

                        if (t.Seconds > 9)
                        {
                            tempLenght += t.Seconds;
                        }
                        else
                        {
                            tempLenght += "0" + t.Seconds;
                        }
                    }
                }

                return "Lenght: " + tempLenght;
            }
        }

        public string PublishedDate
        {
            get
            {
                string temp = Posted;

                if (Posted.Contains(":"))
                {
                    temp = temp.Substring(0, temp.LastIndexOf(":"));
                    string temp2 = temp.Substring(temp.Length - 10);
                    temp = temp.Substring(0, temp.Length - 10);
                    temp = temp + Environment.NewLine + temp2;
                }

                return temp;
            }
        }

        public string PublishedDate2
        {
            get
            {
                string temp = Posted;
                temp = temp.Replace(" AM", "");
                temp = temp.Replace(" PM", "");
                return temp;
            }
        }

    }
}

